home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / bin / ubiquity < prev    next >
Text File  |  2009-10-28  |  5KB  |  136 lines

  1. #! /usr/bin/python
  2.  
  3. # Wrapper script to run Ubiquity as root using the appropriate privilege
  4. # escalation method for the frontend.
  5.  
  6. import sys
  7. import os
  8. import syslog
  9. import subprocess
  10.  
  11. sys.path.insert(0, '/usr/lib/ubiquity')
  12.  
  13. from ubiquity import osextras
  14.  
  15. def main():
  16.     newargv = []
  17.     desktop = None
  18.     frontend = None
  19.     toexec = []
  20.  
  21.     i = 1
  22.     while i < len(sys.argv):
  23.         if sys.argv[i] == '--desktop':
  24.             desktop = sys.argv[i + 1]
  25.             i += 2
  26.             # strip option and argument from newargv
  27.             continue
  28.         elif not sys.argv[i].startswith('-'):
  29.             frontend = sys.argv[i]
  30.         newargv.append(sys.argv[i])
  31.         i += 1
  32.  
  33.     if os.getuid() == 0:
  34.         # no privilege escalation required
  35.         inner = ['/usr/lib/ubiquity/bin/ubiquity']
  36.         inner.extend(newargv)
  37.  
  38.         # Lock HAL's storage subsystem (or DeviceKit-disks).
  39.         if osextras.find_on_path('devkit-disks'):
  40.             toexec.extend(['devkit-disks', '--inhibit', '--'])
  41.             toexec.extend(inner)
  42.         elif osextras.find_on_path('hal-lock'):
  43.             toexec.extend(['hal-lock',
  44.                            '--interface', 'org.freedesktop.Hal.Device.Storage',
  45.                            '--exclusive', '--run'])
  46.             # hal-lock has irritating argument passing conventions.
  47.             toexec.append(' '.join(inner))
  48.         else:
  49.             toexec.extend(inner)
  50.     else:
  51.         if frontend is None:
  52.             # Try to detect which frontend will be used by looking for a
  53.             # frontend module.
  54.             import imp
  55.             import ubiquity.frontend
  56.             frontend_names = ['mythbuntu_ui', 'gtk_ui', 'kde_ui']
  57.             for f in frontend_names:
  58.                 try:
  59.                     imp.find_module(f, ubiquity.frontend.__path__)
  60.                     frontend = f
  61.                     break
  62.                 except ImportError:
  63.                     pass
  64.  
  65.         if frontend in ('gtk_ui', 'mythbuntu_ui'):
  66.             toexec = ['gksudo', '--preserve-env']
  67.             if desktop:
  68.                 toexec.extend(['--desktop', desktop])
  69.             toexec.append('--')
  70.         elif frontend == 'kde_ui':
  71.             kdesu = None
  72.             if osextras.find_on_path('kdesu'):
  73.                 kdesu = 'kdesu'
  74.             elif osextras.find_on_path('kdesudo'):
  75.                 kdesu = 'kdesudo'
  76.             elif os.path.exists('/usr/lib/kde4/libexec/kdesu'):
  77.                 kdesu = '/usr/lib/kde4/libexec/kdesu'
  78.             if kdesu:
  79.                 toexec = [kdesu, '--nonewdcop', '--']
  80.             else:
  81.                 toexec = ['sudo', '-E']
  82.             #temporarily force sudo until we work out why kdesudo stops it passing partitioning stage
  83.             toexec = ['sudo', '-E']
  84.         else:
  85.             toexec = ['sudo', '-E']
  86.  
  87.         # re-exec ourselves first time round, to cope with broken argument
  88.         # handling in kdesu
  89.         toexec.append(sys.argv[0])
  90.         toexec.extend(newargv)
  91.  
  92.     # Workaround for hang on relatively low-memory PS3 systems (#106683).
  93.     # Apparently killing a few processes up-front helps.
  94.     try:
  95.         lowmem = False
  96.         archdetect = subprocess.Popen(['archdetect'], stdout=subprocess.PIPE)
  97.         arch = archdetect.communicate()[0].strip()
  98.         if arch == 'powerpc/ps3':
  99.             meminfo = open('/proc/meminfo')
  100.             try:
  101.                 for line in meminfo:
  102.                     if line.startswith('MemTotal:'):
  103.                         mem = int(line.split()[1])
  104.                         if mem <= 262144:
  105.                             lowmem = True
  106.                             break
  107.             finally:
  108.                 meminfo.close()
  109.         if lowmem:
  110.             syslog.syslog("Low memory: killing processes to work around hang")
  111.             if frontend == 'gtk_ui':
  112.                 for session_process in ('evolution-alarm-notify',
  113.                                         'gnome-cups-icon',
  114.                                         'jockey-gtk',
  115.                                         'update-notifier'):
  116.                     subprocess.call(['gnome-session-remove',
  117.                                      session_process])
  118.             if os.getuid() == 0:
  119.                 subprocess.call(['/etc/init.d/cupsys', 'stop'])
  120.                 subprocess.call(['/etc/init.d/hplip', 'stop'])
  121.             else:
  122.                 subprocess.call(['sudo', '/etc/init.d/cupsys', 'stop'])
  123.                 subprocess.call(['sudo', '/etc/init.d/hplip', 'stop'])
  124.     except (KeyboardInterrupt, SystemExit):
  125.         raise
  126.     except:
  127.         pass
  128.  
  129.     if 'UBIQUITY_WRAPPER_DEBUG' in os.environ:
  130.         print >>sys.stderr, toexec
  131.     os.execvp(toexec[0], toexec)
  132.     sys.exit(127)
  133.  
  134. if __name__ == '__main__':
  135.     main()
  136.